package com.googlecode.mailnet.emf.netmodel.visualization.importance;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Shape;
import org.eclipse.swt.graphics.Color;

import com.googlecode.mailnet.emf.netmodel.simulation.NodeStatistics;
import com.googlecode.mailnet.emf.netmodel.simulation.SimulationContext;
import com.googlecode.mailnet.emf.netmodel.visualization.ShapeDecorator;
import com.googlecode.mailnet.info.INodeInfo;

public class ImportanceNodeDecorator extends ShapeDecorator {
	
	INodeInfo nodeInfo;
	SimulationContext context;
	
	public ImportanceNodeDecorator(INodeInfo nodeInfo, SimulationContext context) {
		this.nodeInfo = nodeInfo;
		this.context = context;
	}
	
	@Override
	public boolean outlineShape(Shape shape, Graphics g) {
		shape.setLineStyle(Graphics.LINE_SOLID);
		shape.setForegroundColor(new Color(null, 100, 100, 100));
		shape.setLineStyle(nodeInfo.isBroken() ? Graphics.LINE_DASH : Graphics.LINE_SOLID);
		shape.setLineWidth(1);
		return super.outlineShape(shape, g);
	}

	public boolean fillShape(Shape shape, Graphics g) {
		NodeStatistics nodeStat = context.getStatistics().getNodeStats(nodeInfo.getNode());
		double importance = nodeStat.importance;

		long colorBrightness = Math.round(importance * 85.0);
		Color color = new Color(null, 170 + (int)colorBrightness, 170 - (int)colorBrightness, 170 - (int)colorBrightness);
		shape.setBackgroundColor(color);
		return false;
	}
}
